
$(function () {
  $('#topBtn').click(setTop)
  $('#wonderfulBtn').click(setWonderful)
  $('#delBtn').click(setDel)
})
function like(but, entityType, entityId, entityUserId, postId) {
  $.post(
      CONTEXT_PATH + "/like",
      {"entityType":entityType, "entityId":entityId, "entityUserId":entityUserId, "postId":postId},
      function (data) {
        console.log(data)
        data = $.parseJSON(data)
        if(data.code == 0) {
          $(but).children("i").text(data.likeCount);
          $(but).children("b").text(data.likeStatus==1?'已赞':"赞");
        } else {
          alert(data.msg);
        }
      }
  )
}

function setWonderful() {
  $.post(CONTEXT_PATH + '/discuss-post/wonderful',
      {"postId":$('#postId').val()},
      function (result) {
        data = $.parseJSON(result);
        if(data.code == 0) {
          $("#wonderfulBtn").attr("disabled", "disabled");
        } else {
          alert(data.msg);
        }
      })
}

function setDel() {
  $.post(CONTEXT_PATH + '/discuss-post/delete',
      {"postId":$('#postId').val()},
      function (result) {
        data = $.parseJSON(result);
        if(data.code == 0) {
          location.href = CONTEXT_PATH + "/index";
        } else {
          alert(data.msg);
        }
      })
}

function setTop() {
  $.post(CONTEXT_PATH + '/discuss-post/top',
      {"postId":$('#postId').val()},
      function (result) {
        data = $.parseJSON(result);
        if(data.code == 0) {
          $("#topBtn").attr("disabled", "disabled");
        } else {
          alert(data.msg);
        }
      })
}